﻿Ext.define('app.prm.document.Version',
{
    extend: 'Ext.window.Window',
    autoScroll: true,
    modal: true,
    title: '文档版本',
    //maximized: true,
    width: 600,
    height: 400,
    layout: 'fit',
    bodyStyle: 'padding:2px',
    documentId: 0,
    initComponent: function () {
        var me = this;
        me.items = [me.getVersionGrid()];
        me.callParent();
    },
    getVersionGrid: function () {
        var me = this;
        if (!this.versionGrid) {
            this.versionGrid = new Ext.grid.Panel({
                border: false,
                viewConfig: {
                    enableTextSelection: true //可以复制单元格文字
                },
                forceFit: true,
                store: Ext.create("app.ux.PrmStore", { url: '/api/services/app/document/GetDocumentVersion', filter: { documentId: me.documentId } }),
                columns: [
                    { header: "名称", dataIndex: 'name' },
                    { header: "大小(kb)", dataIndex: 'length' },
                    { header: "类型", dataIndex: 'extension' },
                    {
                        header: "版本", dataIndex: 'version', renderer: function (value, p, record) {
                            return value.toFixed(2);
                        }
                    },
                    {
                        header: "创建时间", dataIndex: 'creationTime', renderer: function (value, p, record) {
                            return Ext.util.Format.date(value, 'Y-m-d');
                        }
                    },
                    { header: "创建人", dataIndex: 'creationUser' },
                    {
                        xtype: 'actioncolumn',
                        width: 70,
                        header: '操作',
                        items: [
                        {
                            icon: '/Content/images/download.gif',
                            tooltip: '下载',
                            handler: function (grid, rowIndex, colIndex) {
                                var record = grid.store.getAt(rowIndex);

                                window.location.href = '/api/services/app/document/GetFile?path=' + record.data.fullUrl;
                            }
                        },
                        {
                            iconCls: 'delete',
                            tooltip: '删除文档',
                            handler: function (grid, rowIndex, colIndex)
                            {
                                var record = grid.store.getAt(rowIndex);
                                App.AjaxDelete('/api/services/app/document/RemoveDocumentVersion?versionId=' + record.data.id, function () {
                                    grid.store.remove(record);
                                });
                            }
                        }
                        ]
                    }
                ]
            });
        }
        return this.versionGrid;
    }
});